<template>
  <div class="waterfallsFlow clear">
    瀑布流
    <ul class="flow-left" id="flowLeft">
      <li v-for="(item,index) in itemsA" :key="index">
        <div class="flowImg">
          <img :src="item.src">
        </div>
        <p class="flowText">{{item.flowText}}</p>
        <div class="userInfo">
          <div class="userImg">
            <img :src="item.userImg" alt="">
          </div>
          <div @click="awesome(item)">
            <img class="zan" src="../assets/img/zan.png" alt="">
            <span>{{item.zan}}</span>
          </div>
        </div>
      </li>
    </ul>
    <ul class="flow-right" id="flowRight">
      <li v-for="(item,index) in itemsB" :key="index">
        <div class="flowImg">
          <img :src="item.src">
        </div>
        <p class="flowText">{{item.flowText}}</p>
        <div class="userInfo">
          <div class="userImg">
            <img :src="item.userImg" alt="">
          </div>
          <div>
            <img class="zan" src="../assets/img/zan.png" alt="">
            <span>{{item.zan}}</span>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "Flow",
    data() {
      return {
        waterfallsFlow: [
          {
            src: "../assets/img/flow1.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "../assets/img/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          },
          {
            src: "../assets/img/flow2.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "../assets/img/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          },
          {
            src: "../assets/img/flow3.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "../assets/img/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          },
          {
            src: "../assets/img/flow4.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "../assets/img/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          }, {
            src: "../assets/img/flow2.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "./images/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          },
          {
            src: "../assets/img/flow3.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "./images/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          },
          {
            src: "../assets/img/flow4.png",
            flowText: "梦幻巴黎婚礼梦幻巴黎婚礼梦幻巴黎婚礼",
            userImg: "../assets/img/userImg.png",
            usernmae: "懒猫",
            isawesome: false,
            zan: 0,
          }

        ],
        itemsB: [],
        itemsA: [],
      }
    },
    mounted: function () {
      this.getData()
    },
    methods: {
      getImg: function (url, callback) {

        var img = new Image();
        img.src = url;
        if (img.compltet) {
          console.log('ss')
          callback(img.width, img.height, Number(img.height) / Number(img.width));
        } else {
          img.onload = function () {
            callback(img.width, img.height, Number(img.height) / Number(img.width));
          }
        }
      },
      //瀑布流展示
      getData() {
        let boxA = document.getElementsByClassName('flow-left')[0].clientHeight;
        let boxB = document.getElementsByClassName('flow-right')[0].clientHeight;
        var list = this.waterfallsFlow;

        var that = this;
        for (var i = 0, len = list.length; i < len; i++) {
          (function (j) {
            console.log(list[j])
            that.getImg(list[j].src, function (w, h, r) {
              console.log(ss)
              boxA = document.getElementsByClassName('flow-left')[0].clientHeight;
              boxB = document.getElementsByClassName('flow-right')[0].clientHeight;

              if (boxA > boxB) {
                that.itemsB.push(list[j])
                console.log(list[j])
              } else {
                that.itemsA.push(list[j])
              }
            })
          })(i)
        }
      },
      //点赞
      awesome(item) {
        if (!item.isawesome) {
          item.isawesome = !item.isawesome
          item.zan++
        } else {
          item.isawesome = !item.isawesome
          item.zan--
        }
      }
    }
  }
</script>

<style scoped>
  .clear:after {
    content: '';
    display: block;
    clear: both;
  }

  .flow-left,.flow-right{
    float: left;
    width: 48% ;

    border-radius: 0 0 5px 5px;
  }
  .flow-left>li,.flow-right>li{
    margin-top: .15rem;
    background: #fff;
    box-shadow: 0 0 1px 1px #cacaca;
    -webkit-border-radius: 0 0 8px 8px;
    -moz-border-radius: 0 0 8px 8px;
    border-radius: 0 0 8px 8px;
  }
  .flow-right {
    margin-left: 4%;
  }
  .flowImg {
    width: 100% ;
  }
  .flowImg>img{
    width: 100% ;
    display: block;
  }
  .flowText {
    height: .7rem;
    line-height: .7rem;
    box-sizing: border-box;
    padding: 0 .2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }
  .userInfo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding: 0 .2rem;
    padding-bottom:.2rem ;
  }
  .userImg {
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
  }
  .userImg>img{
    width: 100%;
    height: 100%;
    display: block;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
  }
  .zan {
    width: .4rem;
    height: .4rem;
  }
</style>
